#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

inline char getc() {
    static char buf[1 << 18], *fs, *ft;
    return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 18, stdin)), fs == ft) ? EOF : *fs++;
}

inline int gn() {
    int k = 0, f = 1;
    char c = getc();
    for (; !isdigit(c); c = getc()) if (c == '-') f = -1;
    for (; isdigit(c); c = getc()) k = k * 10 + (c ^ 0x30);
    return k * f;
}

int f[1002], n, p, m;

int main() {
#ifndef LOCAL
    freopen("fibonacci.in", "r", stdin);
    freopen("fibonacci.out", "w", stdout);
#endif
    n = gn(), p = gn(), m = gn();
    f[2] = f[1] = 1;
    for (int i = 1; i <= m; i++) {
        if (i >= 3) (f[i] = f[i - 1] + f[i - 2]) %= p;
        if (f[i] == n) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}